﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApp
{
    public partial class QOrder : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(QOrder), this);
            WebCommon.CheckLogin(this, 0);
        }

        [AjaxPro.AjaxMethod]
        public ReturnDatas<WebApp.BaseDataSvc.QOrder> GetList(bool? deleteFlag, string orderCode, string cCode, DateTime? sDate, DateTime? eDate,
            string orderStatus, int? agent, int? bizMan, int? stowageMethod, string clientName, bool? isDrawback,
            string customsStatus, string checkOffCode, string caseCode, int loginUserId, int loginUserRole, int pageSize, int pageIndex)
        {
            int recordCount = 0;
            int pageCount = 0;
            ReturnDatas<WebApp.BaseDataSvc.QOrder> dls = new ReturnDatas<WebApp.BaseDataSvc.QOrder>();
            dls.RecordCount = recordCount;
            dls.PageCount = pageCount;
            try
            {
                WebApp.BaseDataSvc.TB_User user = Session["User"] as WebApp.BaseDataSvc.TB_User;
                var datas = this.BaseDataProxy.FindOrders2(out recordCount, out pageCount, deleteFlag, orderCode, cCode, sDate, eDate, orderStatus, agent, bizMan,
                    stowageMethod, clientName, isDrawback, customsStatus, checkOffCode, caseCode, user.id, user.role, pageSize, pageIndex);
                dls.DataList = datas;
            }
            catch { }            
            return dls;
        }

        [AjaxPro.AjaxMethod]
        public List<string[]> GetList(int deleteFlag, string orderCode, string cCode, string sDate, string eDate,
            string orderStatus, int agent, int bizMan, int stowageMethod, string clientName, int isDrawback,
            string customsStatus, string checkOffCode, string caseCode, int loginUserId, int loginUserRole, int pageSize, int pageIndex)
        {
            int recordCount = 0;
            int pageCount = 0;
            ReturnDatas<WebApp.BaseDataSvc.QOrder> dls = new ReturnDatas<WebApp.BaseDataSvc.QOrder>();
            dls.RecordCount = recordCount;
            dls.PageCount = pageCount;
            try
            {
                WebApp.BaseDataSvc.TB_User user = Session["User"] as WebApp.BaseDataSvc.TB_User;
                //if (ds != null && ds.Tables.Count > 0)
                //{
                //    List<string[]> rtnList = new List<string[]>();
                //    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                //    {
                //        string sex = "未知";
                //        if (Convert.ToInt16(ds.Tables[0].Rows[i]["Sex"]) == 1)
                //            sex = "男";
                //        else if (Convert.ToInt16(ds.Tables[0].Rows[i]["Sex"]) == 2)
                //            sex = "女";
                //        string departMent = WebCommon.GetNameByXML("~/App_Data/Department.xml", ds.Tables[0].Rows[i]["Department"].ToString());

                //        string link = "<a href=\"#\" onclick=\"choseUser('" + ds.Tables[0].Rows[i]["UName"].ToString() + "'," + ds.Tables[0].Rows[i]["UId"].ToString() + ")\">" + ds.Tables[0].Rows[i]["UName"].ToString() + "</a>";
                //        string op = string.Empty;
                //        if (WebCommon.CheckPermit(user.UId, MId, GDR.Model.EnumType.PermitType.edit))
                //            op = "<a href=\"#\" onclick=\"viewUser(false," + ds.Tables[0].Rows[i]["UId"].ToString() + ")\">编辑</a> ";
                //        if (WebCommon.CheckPermit(user.UId, MId, GDR.Model.EnumType.PermitType.delete))
                //            op += "<a href=\"#\" onclick=\"delUser(" + ds.Tables[0].Rows[i]["UId"].ToString() + ")\">删除</a> ";
                //        if (user.BizType == 5)
                //            op += "<a href=\"#\" onclick=\"window.open('Authorization.aspx?UId=" + ds.Tables[0].Rows[i]["UId"].ToString() + "','','width=500,height=400,scrollbars=1,location=0,status=0,resizable=1')\">授权</a>";

                //        rtnList.Add(new string[] { ds.Tables[0].Rows[i]["UId"].ToString(),link, sex,
                //    departMent,ds.Tables[0].Rows[i]["BizName"].ToString(),ds.Tables[0].Rows[i]["ContactTel"].ToString(),ds.Tables[0].Rows[i]["Email"].ToString(),op});
                //    }
                //    return rtnList;
                //}
            }
            catch { }
            return null;
        }

        public class ReturnDatas<T>
        {
            public IEnumerable<T> DataList { get; set; }
            public int RecordCount { get; set; }
            public int PageCount { get; set; }
        }
    }
}
